home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tde210.zip / CFGCOLOR.C < prev    next >
C/C++ Source or Header  |  1992-11-13  |  12KB  |  461 lines

  1. /*
  2.  * Customize the colors in tde.
  3.  *
  4.  * Author:        Frank Davis
  5.  * Date:          July 21, 1991
  6.  * Compiler:      MSC 6.0a and QuickC 2.51
  7.  *
  8.  * This program is released into the public domain.  You may distribute
  9.  * it freely, Frank Davis
  10.  */
  11.  
  12.  
  13. /********    EXTREMELY IMPORTANT   ************/
  14. /*
  15.  * If you modify tde, it is your responsibility to find the offset of
  16.  * "static int colors" in function "hw_initialize" in file "main.c" in your
  17.  * new executable, tde.exe.
  18.  *
  19.  * If you don't change the default colors, search for the following string (a
  20.  * hexadecimal integer array) in your new executable file:
  21.  *
  22.  *  7000 0700
  23.  *
  24.  * Then, replace COLOR_OFFSET with your new one and recompile tdecfg
  25.  * with the new offset.
  26.  */
  27. /*******     EXTREMELY IMPORTANT   ************/
  28.  
  29.  
  30. #include <bios.h>
  31. #include <dos.h>
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36. #include "tdecfg.h"
  37. #include "cfgcolor.h"
  38.  
  39.  
  40. /*
  41.  * Default color settings.  Incidentally, I'm color blind (mild red-green) and
  42.  * the default colors look fine to me. ;*)
  43.  */
  44. static int colors[2][NUM_COLORS] = {
  45.    { HERC_REVERSE, HERC_NORMAL, HERC_REVERSE, HERC_REVERSE, HERC_HIGH,
  46.      HERC_NORMAL, HERC_NORMAL, HERC_HIGH, HERC_HIGH },
  47.    { COLOR_HEAD, COLOR_TEXT, COLOR_MODE, COLOR_BLOCK, COLOR_MESSAGE,
  48.      COLOR_HELP, COLOR_WRAP, COLOR_EOF, COLOR_CURL }
  49. };
  50.  
  51. extern struct vcfg cfg;         /* video stuff */
  52. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  53.  
  54. int temp_colors[2][NUM_COLORS]; /* play around with colors in this array */
  55. static int index;               /* 0 = Monochrome colors, 1 = color colors */
  56.  
  57.  
  58. /*
  59.  * Name:    tdecolor
  60.  * Date:    July 21, 1991
  61.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  62.  *          variables  2) show the user a color sample  3) make the changes
  63.  *          permanent if desired.
  64.  */
  65. void tdecolor( void )
  66. {
  67.    initialize_color( );
  68.    show_init_sample( );
  69.    change_colors( );
  70. }
  71.  
  72.  
  73. /*
  74.  * Name:    initialize
  75.  * Date:    July 21, 1991
  76.  * Notes:   Set up all of the global variables.
  77.  */
  78. void initialize_color( void )
  79. {
  80. int i, j;
  81.  
  82.    fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
  83.    fread( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
  84.  
  85.    if (cfg.color == FALSE)
  86.       index = 0;
  87.    else
  88.       index = 1;
  89.  
  90.    fields[0].color = temp_colors[index][HELP];
  91.    fields[1].color = temp_colors[index][HEAD];
  92.    fields[2].color = temp_colors[index][TEXT];
  93.    fields[3].color = temp_colors[index][CURL];
  94.    fields[4].color = temp_colors[index][WARNING];
  95.    fields[5].color = temp_colors[index][MODE];
  96.    fields[6].color = temp_colors[index][WRAP];
  97.    fields[7].color = temp_colors[index][CEOF];
  98.    fields[8].color = temp_colors[index][RULER];
  99.    fields[9].color = temp_colors[index][RULER_PTR];
  100.    fields[10].color = temp_colors[index][BLOCK];
  101.    fields[11].color = temp_colors[index][HILITED_FILE];
  102.  
  103.    fields[0].show_me = show_help_color;
  104.    fields[1].show_me = show_fileheader_color;
  105.    fields[2].show_me = show_text_color;
  106.    fields[3].show_me = show_curl_color;
  107.    fields[4].show_me = show_warning_color;
  108.    fields[5].show_me = show_mode_color;
  109.    fields[6].show_me = show_wrapped_color;
  110.    fields[7].show_me = show_eof_color;
  111.    fields[8].show_me = show_ruler_color;
  112.    fields[9].show_me = show_rulerptr_color;
  113.    fields[10].show_me = show_block_color;
  114.    fields[11].show_me = show_hilitedfile_color;
  115. }
  116.  
  117.  
  118. /*
  119.  * Name:    show_init_sample
  120.  * Date:    July 21, 1991
  121.  * Notes:   Draw all of the sample screens.
  122.  */
  123. void show_init_sample( void )
  124. {
  125. char *sample;
  126. int line, i, j, k, l;
  127. char temp[6], num[6];
  128. char far *p;
  129.  
  130.    xygoto( -1, -1 );
  131.    sample = sample_screen[0];
  132.    for (line=0; sample != NULL; ) {
  133.       s_output( (char far *)sample, line, 0, 7 );
  134.       sample = sample_screen[++line];
  135.    }
  136.    for (i=0; i<NUM_COLORS; i++)
  137.       (*fields[i].show_me)();
  138.    sample = field_screen[0];
  139.    for (line=12, i=1; sample != NULL; line++,i++) {
  140.       s_output( (char far *)sample, line, 0, 7 );
  141.       sample = field_screen[i];
  142.    }
  143.    p = (char far *)temp;
  144.    for (i=0,k=0,line=17; i<8; i++, line++) {
  145.       for (j=0,l=0; j<16; j++, k++,l+=5) {
  146.          color_number( temp, k );
  147.          s_output( p, line, l, k );
  148.       }
  149.    }
  150.    for (i=0; i<NUM_COLORS; i++) {
  151.       color_number( temp, fields[i].color );
  152.       s_output( p, fields[i].line, fields[i].col, fields[i].color );
  153.    }
  154. }
  155.  
  156.  
  157. /*
  158.  * Name:    color_number
  159.  * Date:    July 21, 1991
  160.  * Passed:  dest:  buffer to store the color sample
  161.  *          num:   attribute number
  162.  * Notes:   Show the use what the foreground and background colors look like.
  163.  */
  164. void color_number( char *dest, int num )
  165. {
  166. int i, j, k;
  167. char temp[6];
  168.  
  169.    strcpy( dest, "[   ]" );
  170.    itoa( num, temp, 10 );
  171.    i = strlen( temp );
  172.    j = 4 - i;
  173.    for (k=0; i > 0; i--,j++, k++)
  174.       dest[j] = temp[k];
  175. }
  176.  
  177.  
  178. /*
  179.  * Name:    current_color_number
  180.  * Date:    July 21, 1991
  181.  * Passed:  dest:  buffer to store the color sample
  182.  *          num:   attribute number
  183.  * Notes:   Put '*' around the sample color to give the user an idea of where
  184.  *          the current field is.
  185.  */
  186. void current_color_number( char *dest, int num )
  187. {
  188. int i, j, k;
  189. char temp[6];
  190.  
  191.    strcpy( dest, "*   *" );
  192.    itoa( num, temp, 10 );
  193.    i = strlen( temp );
  194.    j = 4 - i;
  195.    for (k=0; i > 0; i--,j++, k++)
  196.       dest[j] = temp[k];
  197. }
  198.  
  199.  
  200. /*
  201.  * Name:    show_help_color
  202.  * Date:    July 21, 1991
  203.  */
  204. void show_help_color( void )
  205. {
  206. int color;
  207. int line, len;
  208.  
  209.    color = fields[0].color;
  210.    for (line=1; line <10; line++)
  211.       hlight_line( 1, line, 37, color );
  212.    hlight_line( 1,  10, 13, color );
  213.    hlight_line( 25, 10, 13, color );
  214. }
  215.  
  216.  
  217. /*
  218.  * Name:    show_fileheader_color
  219.  * Date:    July 21, 1991
  220.  */
  221. void show_fileheader_color( void )
  222. {
  223.    hlight_line( 41, 1, 38, fields[1].color );
  224. }
  225.  
  226.  
  227. /*
  228.  * Name:    show_text_color
  229.  * Date:    July 21, 1991
  230.  */
  231. void show_text_color( void )
  232. {
  233. int color;
  234.  
  235.    color = fields[2].color;
  236.    hlight_line( 41, 3, 38, color );
  237.    hlight_line( 41, 5, 38, color );
  238. }
  239.  
  240.  
  241. /*
  242.  * Name:    show_curl_color
  243.  * Date:    July 21, 1991
  244.  */
  245. void show_curl_color( void )
  246. {
  247.    hlight_line( 41, 4, 38, fields[3].color );
  248. }
  249.  
  250.  
  251. /*
  252.  * Name:    show_warning_color
  253.  * Date:    July 21, 1991
  254.  */
  255. void show_warning_color( void )
  256. {
  257.    hlight_line( 41, 9, 38, fields[4].color );
  258. }
  259.  
  260.  
  261. /*
  262.  * Name:    show_mode_color
  263.  * Date:    July 21, 1991
  264.  */
  265. void show_mode_color( void )
  266. {
  267.    hlight_line( 41, 10, 26, fields[5].color );
  268. }
  269.  
  270.  
  271. /*
  272.  * Name:    show_wrapped_color
  273.  * Date:    July 21, 1991
  274.  */
  275. void show_wrapped_color( void )
  276. {
  277.    hlight_line( 67, 10, 12, fields[6].color );
  278. }
  279.  
  280.  
  281. /*
  282.  * Name:    show_eof_color
  283.  * Date:    July 21, 1991
  284.  */
  285. void show_eof_color( void )
  286. {
  287.    hlight_line( 41, 8, 38, fields[7].color );
  288. }
  289.  
  290.  
  291. /*
  292.  * Name:    show_ruler_color
  293.  * Date:    July 21, 1991
  294.  */
  295. void show_ruler_color( void )
  296. {
  297.    hlight_line( 41, 2, 21, fields[8].color );
  298.    hlight_line( 63, 2, 16, fields[8].color );
  299. }
  300.  
  301.  
  302. /*
  303.  * Name:    show_rulerptr_color
  304.  * Date:    July 21, 1991
  305.  */
  306. void show_rulerptr_color( void )
  307. {
  308.    hlight_line( 62, 2, 1, fields[9].color );
  309. }
  310.  
  311.  
  312. /*
  313.  * Name:    show_block_color
  314.  * Date:    July 21, 1991
  315.  */
  316. void show_block_color( void )
  317. {
  318. int color;
  319. int line;
  320.  
  321.    color = fields[10].color;
  322.    for (line=6; line <8; line++)
  323.       hlight_line( 41, line, 38, color );
  324. }
  325.  
  326.  
  327. /*
  328.  * Name:    show_hilitedfile_color
  329.  * Date:    July 21, 1991
  330.  */
  331. void show_hilitedfile_color( void )
  332. {
  333.    hlight_line( 14, 10, 11, fields[11].color );
  334. }
  335.  
  336.  
  337. /*
  338.  * Name:    change_colors
  339.  * Date:    July 21, 1991
  340.  * Notes:   Real workhorse function of the utility.  Get a key and then
  341.  *          figure out what to do with it.
  342.  */
  343. void change_colors( void )
  344. {
  345. int c;
  346. int area;
  347. int color;
  348. int new_color;
  349. int i;
  350. char temp[6];
  351. char far *p;
  352.  
  353.    p = (char far *)temp;
  354.    area = 0;
  355.    current_color_number( temp, fields[area].color );
  356.    s_output( p, fields[area].line, fields[area].col, fields[area].color );
  357.    xygoto( fields[area].col+3, fields[area].line );
  358.    for (c=0; c != F3  &&  c != F10  &&  c != ESC;) {
  359.       new_color = FALSE;
  360.       c = getkey( );
  361.       switch (c) {
  362.          case RTURN :
  363.          case DOWN  :
  364.             color_number( temp, fields[area].color );
  365.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  366.             ++area;
  367.             if (area > 11)
  368.                area = 0;
  369.             current_color_number( temp, fields[area].color );
  370.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  371.             xygoto( fields[area].col+3, fields[area].line );
  372.             break;
  373.          case UP    :
  374.             color_number( temp, fields[area].color );
  375.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  376.             --area;
  377.             if (area < 0)
  378.                area = 11;
  379.             current_color_number( temp, fields[area].color );
  380.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  381.             xygoto( fields[area].col+3, fields[area].line );
  382.             break;
  383.          case LEFT :
  384.             --fields[area].color;
  385.             if (fields[area].color < 0)
  386.                fields[area].color = 127;
  387.             new_color = TRUE;
  388.             break;
  389.          case RIGHT :
  390.             ++fields[area].color;
  391.             if (fields[area].color > 127)
  392.                fields[area].color = 0;
  393.             new_color = TRUE;
  394.             break;
  395.          case PGUP :
  396.             fields[area].color -= 16;
  397.             if (fields[area].color < 0)
  398.                fields[area].color = (fields[area].color & 0x000f) + 0x70;
  399.             new_color = TRUE;
  400.             break;
  401.          case PGDN :
  402.             fields[area].color += 16;
  403.             if (fields[area].color > 127)
  404.                fields[area].color = fields[area].color & 0x000f;
  405.             new_color = TRUE;
  406.             break;
  407.          case F2 :
  408.  
  409.             /*
  410.              * get back the original colors and display
  411.              */
  412.             fields[0].color = colors[index][HELP];
  413.             fields[1].color = colors[index][HEAD];
  414.             fields[2].color = colors[index][TEXT];
  415.             fields[3].color = colors[index][CURL];
  416.             fields[4].color = colors[index][WARNING];
  417.             fields[5].color = colors[index][MODE];
  418.             fields[6].color = colors[index][WRAP];
  419.             fields[7].color = colors[index][CEOF];
  420.             fields[8].color = colors[index][RULER];
  421.             fields[9].color = colors[index][RULER_PTR];
  422.             fields[10].color = colors[index][BLOCK];
  423.             fields[11].color = colors[index][HILITED_FILE];
  424.             for (i=0; i<NUM_COLORS; i++) {
  425.                color_number( temp, fields[i].color );
  426.                s_output( p, fields[i].line, fields[i].col, fields[i].color );
  427.                (*fields[i].show_me)();
  428.             }
  429.             current_color_number( temp, fields[area].color );
  430.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  431.             break;
  432.       }
  433.       if (new_color) {
  434.          current_color_number( temp, fields[area].color );
  435.          s_output( p, fields[area].line, fields[area].col, fields[area].color );
  436.          (*fields[area].show_me)();
  437.       }
  438.    }
  439.  
  440.    /*
  441.     * write changes to "tde.exe" if user presses F10.
  442.     */
  443.    if (c == F10) {
  444.       temp_colors[index][HELP]         = fields[0].color;
  445.       temp_colors[index][HEAD]         = fields[1].color;
  446.       temp_colors[index][TEXT]         = fields[2].color;
  447.       temp_colors[index][CURL]         = fields[3].color;
  448.       temp_colors[index][WARNING]      = fields[4].color;
  449.       temp_colors[index][MODE]         = fields[5].color;
  450.       temp_colors[index][WRAP]         = fields[6].color;
  451.       temp_colors[index][CEOF]         = fields[7].color;
  452.       temp_colors[index][RULER]        = fields[8].color;
  453.       temp_colors[index][RULER_PTR]    = fields[9].color;
  454.       temp_colors[index][BLOCK]        = fields[10].color;
  455.       temp_colors[index][HILITED_FILE] = fields[11].color;
  456.       fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
  457.       fwrite( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
  458.    }
  459.    cls( );
  460. }
  461.